package com.wl.eb.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wl.eb.service.IndexService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Map;
/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2021/12/2 16:37
 */
@Controller
@RequestMapping("/index")
public class IndexController {
    @Resource
    private IndexService indexService;
    @GetMapping("/index")
    public String index(Model model,
                        @RequestParam(value = "page",defaultValue = "1") int page) {
        System.out.println("=====进入IndexController的index方法,page："+page);
        //1.查询首页需要展示的数据
        Map<String, Object> result = indexService.index(page);
        System.out.println("=====result:==="+result);
        //2.将数据放到model
        model.addAttribute("productPage", (Page)result.get("ebProductPage"));
        model.addAttribute("newsPage",(Page)result.get("ebNewsPage"));
        //model.addAttribute("bigs", (List)result.get("bigs"));
        //model.addAttribute("smalls",(List)result.get("smalls"));
        //3.返回view---视图  html
        return "index";//templates/index.html
    }
}
